import axios from 'axios'
/*
发送异步的ajax请求模块
封装的axios库
*/

axios.defaults.headers['Content-Type'] = 'raw';

axios.interceptors.request.use(request => {
  console.log("request")
  if (localStorage.getItem('token')) {
    request.headers = {
      'token': localStorage.getItem('token')
    }
  }
  return request;
}, function (error) {
  return Promise.reject(error);
});


export let POST = async function (url, data) {
  let res = await axios({
    url,
    method: "post",
    data
  })
  return res.data;
}

export let GET = async function (url, params) {
  let res = await axios({
    url,
    method: "get",
    params
  })
  return res.data;
}